<template>
  <div class="app-container">
    <ve-line :data="chartDatas" :settings="chartSettings"></ve-line>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="隧道名称" prop="tunnelName">
        <el-input
          v-model="queryParams.tunnelName"
          placeholder="请输入隧道名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="道路名称" prop="roadName">
        <el-input
          v-model="queryParams.roadName"
          placeholder="请输入道路名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="里程桩号" prop="mileageNumber">
        <el-input
          v-model="queryParams.mileageNumber"
          placeholder="请输入里程桩号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设施名称" prop="facilityName">
        <el-select v-model="queryParams.facilityName" placeholder="请输入设施名称" clearable :style="{width: '100%'}">
          <el-option v-for="(item, index) in fieldfacility" :key="index" :label="item.label"
                     :value="item.value" :disabled="item.disabled"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="检查日期" prop="inspectionDate">
        <el-date-picker clearable
                        v-model="queryParams.inspectionDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择检查日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['civil:regularcheck:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['civil:regularcheck:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="checkList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="regularCheckId" />
      <el-table-column label="道路名称" align="center" prop="roadName" />
      <el-table-column label="隧道名称" align="center" prop="tunnelName" />
      <el-table-column label="养护机构" align="center" prop="maintenanceOrganization" />
      <el-table-column label="上次检查日期" align="center" prop="lastInspectionDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.lastInspectionDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="本次检查日期" align="center" prop="inspectionDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.inspectionDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="里程桩号" align="center" prop="mileageNumber" />
      <el-table-column label="设施名称" align="center" prop="facilityName" />
      <el-table-column label="状况值" align="center" prop="positionNumber" />
      <el-table-column label="检查人员" align="center" prop="inspection" />
      <el-table-column label="操作"
                       align="center"
                       width="200"
                       class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['civil:regularcheck:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleCheck(scope.row)"
            v-hasPermi="['civil:regularcheck:edit']"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!--查看定期检查内容对话框-->
   <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-col :span="12">
            <el-form-item label="隧道名称">
              <el-input v-model="form.tunnelName" v-bind:disabled="true"/>
            </el-form-item>
          </el-col>
        <el-col :span="12">
            <el-form-item label="隧道编码" >
              <el-input v-model="form.tunnelId" v-bind:disabled="true"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="道路名称" >
              <el-input v-model="form.roadName"  v-bind:disabled="true"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="道路编码" >
              <el-input v-model="form.roadId" v-bind:disabled="true" />
            </el-form-item>
          </el-col>
        <el-col>
        <el-form-item label="管养单位"  >
          <el-input v-model="form.maintenanceOrganization" v-bind:disabled="true" />
        </el-form-item>
        </el-col>
        <el-col>
        <el-form-item label="上次检查日期" >
          <el-date-picker clearable
                          v-model="form.lastInspectionDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          v-bind:disabled="true">
          </el-date-picker>
        </el-form-item>
        </el-col>
        <el-col>
        <el-form-item label="本次检查日期" >
          <el-date-picker clearable
                          v-model="form.inspectionDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          v-bind:disabled="true">
          </el-date-picker>
        </el-form-item>
        </el-col>
        <el-col>
        <el-form-item label="里程桩号" >
          <el-input v-model="form.mileageNumber" v-bind:disabled="true" />
        </el-form-item>
        <el-form-item label="设施名称" >
          <el-input v-model="form.facilityName" v-bind:disabled="true" />
        </el-form-item>
        <el-form-item label="检查位置" >
          <el-input v-model="form.defectLocation"  v-bind:disabled="true"/>
        </el-form-item>
        <el-form-item label="检查内容" >
          <el-input v-model="form.examinationContent" v-bind:disabled="true" />
        </el-form-item>
        <el-form-item label="状况描述" >
          <el-input v-model="form.positionDescribe" v-bind:disabled="true" />
        </el-form-item>
        <el-form-item label="状况值" >
          <el-input v-model="form.positionNumber" v-bind:disabled="true" />
        </el-form-item>
          <el-form-item label="上传图片">
            <image-upload v-model="form.picture"   v-bind:disabled="true"/>
          </el-form-item>
        <el-form-item label="检查人员">
          <el-input v-model="form.inspection" v-bind:disabled="true" />
        </el-form-item>
        <el-form-item label="记录人">
          <el-input v-model="form.record" v-bind:disabled="true"/>
        </el-form-item>
        </el-col>
      </el-form>
     <div slot="footer" class="dialog-footer">
       <el-button @click="cancel">取消查看</el-button>
     </div>
    </el-dialog>
  </div>
</template>

<script>

import { listCheck, getCheck, delCheck,updateCheck, pictureUp} from "@/api/civil/regularcheck";

export default {
  name: "Check",
  data() {

    this.chartSettings = {
      stack: {
        '设施名称': ['','']
      }
    }
    return {
      chartData:[],
      chartDatas: {
        columns: ['设施名称', '最大值','最小值'],
        rows: [
        ]
      },
      //公路名称
      roadName: undefined,
      // 公路选项
      roadOptions: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      checkList: [],
      // 弹出层标题
      title: "",
      //是否显示产看的弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        tunnelName: null,
        tunnelId: null,
        roadName: null,
        roadId: null,
        maintenanceOrganization: null,
        lastInspectionDate: null,
        inspectionDate: null,
        mileageNumber: null,
        facilityName: null,
        defectLocation: null,
        examinationContent: null,
        positionDescribe: null,
        positionNumber: null,
        picture: null,
        inspection: null,
        record: null
      },
      // 表单参数
      form: {},


      fieldfacility: [{
        "label": "洞口",
        "value": "洞口"
      }, {
        "label": "洞门",
        "value": "洞门"
      },{
        "label": "衬砌",
        "value": "衬砌"
      },{
        "label": "路面",
        "value": "路面"
      },{
        "label": "检修道",
        "value": "检修道"
      },{
        "label": "排水设施",
        "value": "排水设施"
      },{
        "label": "吊顶及预埋件",
        "value": "吊顶及预埋件"
      },{
        "label": "装饰物",
        "value": "装饰物"
      }, {
        "label": "交通标志/标线",
        "value": "交通标志/标线"
      }
      ],
      // 表单校验
      rules: {
        tunnelName:[
          {required:true, message:"隧道名称为必填项", trigger:"blur"}
          ],
        tunnelId:[
          {required:true, message:"隧道编码为必填项", trigger:"blur"}
        ],
        roadName:[
          {required:true, message:"道路名称为必填项", trigger:"blur"}
        ],
        roadId:[
          {required:true, message:"道路编码为必填项", trigger:"blur"}
        ],
        maintenanceOrganization:[
          {required:true, message:"管养单位为必填项", trigger:"blur"}
        ],
        lastInspectionDate:[
          {required:true, message:"上次检查日期为必填项", trigger:"blur"}
        ],
        inspectionDate:[
          {required:true, message:"本次检查日期为必填项", trigger:"blur"}
        ],
        mileageNumber:[
          {required:true, message:"里程桩号为必填项", trigger:"blur"}
        ],
        facilityName:[
          {required:true, message:"设施名称为必填项", trigger:"blur"}
        ],
        defectLocation:[
          {required:true, message:"检查位置为必填项", trigger:"blur"}
        ],
        examinationContent:[
          {required:true, message:"检查内容为必填项", trigger:"blur"}
        ],
        positionDescribe:[
          {required:true, message:"状况描述为必填项", trigger:"blur"}
        ],
        positionNumber:[
          {required:true, message:"状况值为必填项", trigger:"blur"},
          { pattern: /^([0-4])$/, message: '状况值为0-4的整数'}
        ],
        inspection:[
          {required:true, message:"请填写检查人员姓名", trigger:"blur"}
        ],
        record:[
          {required:true, message:"请填写记录人员姓名", trigger:"blur"}
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询定期检查列表 */
    getList() {
      this.loading = true;
      listCheck(this.queryParams).then(response => {
        this.checkList = response.rows;
        this.total = response.total;
        this.chartData=response.rows;
        this.chartDatas.rows.push({
          '设施名称': this.checkList[0].facilityName, '最大值': this.checkList[0].positionNumber, '最小值': this.checkList[this.chartData.length-1].positionNumber
        })
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        regularCheckId: null,
        tunnelName: null,
        tunnelId: null,
        roadName: null,
        roadId: null,
        maintenanceOrganization: null,
        lastInspectionDate: null,
        inspectionDate: null,
        mileageNumber: null,
        facilityName: null,
        defectLocation: null,
        examinationContent: null,
        positionDescribe: null,
        positionNumber: null,
        picture: null,
        inspection: null,
        record: null,
        roadIds: [],
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.regularCheckId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const regularCheckId = row.regularCheckId || this.ids
      getCheck(regularCheckId).then(response => {
        this.form = response.data;
        this.openadd = true;
        this.title = "修改分项技术状况评定记录";
      });
    },
    /** 查看按钮操作 */
    handleCheck(row) {
      this.reset();
      const regularCheckId = row.regularCheckId || this.ids
      getCheck(regularCheckId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "查看分项技术状况评定记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.regularCheckId != null) {
            updateCheck(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.openadd = false;
              this.getList();
            });
          } else {
            addCheck(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.openadd = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const regularCheckIds = row.regularCheckId || this.ids;
      this.$modal.confirm('是否确认删除编号为"' + regularCheckIds + '"的数据项？').then(function() {
        return delCheck(regularCheckIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('civil/regularcheck/export', {
        ...this.queryParams
      }, `check_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style>
</style>
